/**
 * Comments路由模块
 */

/**
 * @swagger
 * tags:
 *   - name: 评论路由
 *     description: 评论管理相关操作
 * /comments:
 *   post:
 *     summary: 创建新评论
 *     operationId: createComments
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             $ref: '#/components/schemas/Comments'
 *     responses:
 *       '201':
 *         description: 评论创建成功
 *         content:
 *           application/json:
 *             schema:
 *               $ref: '#/components/schemas/Comments'
 *
 * /comments/{id}:
 *   get:
 *     summary: 获取指定ID的评论详情
 *     operationId: getCommentById
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *           format: int64
 *         description: 评论ID
 *     responses:
 *       '200':
 *         description: 成功返回评论详情
 *         content:
 *           application/json:
 *             schema:
 *               $ref: '#/components/schemas/Comments'
 *
 * components:
 *   schemas:
 *     Comments:
 *       required:
 *         - id
 *         - user_id
 *         - course_id
 *         - content
 *         # 可添加更多必填字段...
 *       type: object
 *       properties:
 *         id:
 *           type: integer
 *           format: int64
 *           example: 100
 *           description: 评论ID
 *         user_id:
 *           type: string
 *           description: 用户ID
 *         course_id:
 *           type: integer
 *           format: int64
 *           description: 课程ID
 *         content:
 *           type: string
 *           description: 评论内容
 *     
 *         # 其他属性...
 *         
 *         createdAt:
 *           type: string
 *           format: date-time
 *           description: 评论创建时间
 *         updatedAt:
 *           type: string
 *           format: date-time
 *           description: 评论最后更新时间
 */

 var express = require("express");
 var router = express.Router();
 
 const comments = require("../controller/comments");
 const auth = require("../controller/auth");
 
 
 //定义路由
 
 //守卫路由：所有路由必须执行权限控制的判断
 router.all("*", auth.isLogin);

 /**
 * @swagger
 * /comments/count:
 *   get:
 *     tags:
 *       - 评论路由
 *     summary: 获取评论总数
 *     description: 返回系统中指定课程评论的总数量
 *     responses:
 *       200:
 *         description: "请求成功，返回评论总数"
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   format: int32
 *                 msg:
 *                   type: string
 *                 data:
 *                   type: object
 *                   properties:
 *                     total:
 *                       type: integer
 *                       description: 评论总数
 */
  router.get("/count", auth.isAdmin, comments.getCount);

  
  router.get("/countAll", auth.isAdmin, comments.getCountAll);
 
 //TODO:增加新的功能，及增加对应的路由、控制器以及访问数据库的数据模型

/**
 * @swagger
 * /comments/{id}:
 *   get:
 *     tags:
 *       - 评论路由
 *     summary: 获取指定ID的评论信息
 *     description: 根据用户内部ID返回评论详细信息
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *           format: int64
 *         description: 要查询评论的内部ID
 *     responses:
 *       200:
 *         description: "请求成功，返回评论信息"
 *         content:
 *           application/json:
 *             schema:
 *               $ref: '#/components/schemas/Comments'
 */
 router.get("/:id",comments.find);
/**
 * @swagger
 * /comments:
 *   post:
 *     tags:
 *       - 评论路由
 *     summary: 新增评论信息
 *     description: 添加新的评论信息并返回新增评论的ID
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             $ref: "#/components/schemas/CourseSchema"
 *     security:
 *       - BearerAuth: []
 *     responses:
 *       200:
 *         description: "请求成功，返回新增评论的ID"
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   format: int32
 *                 msg:
 *                   type: string
 *                 data:
 *                   type: integer
 *                   format: int64
 *                   description: 新增评论的ID
 */
 router.post("/", comments.add);
/**
 * @swagger
 * /comments/{id}:
 *   delete:
 *     tags:
 *       - 评论路由
 *     summary: 删除指定ID的评论信息
 *     description: 根据评论的内部ID删除评论信息，并返回受影响的记录数
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *           format: int64
 *         description: 待删除评论的内部ID
 *     responses:
 *       200:
 *         description: "请求成功，返回受影响的记录数"
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   format: int32
 *                 msg:
 *                   type: string
 *                 data:
 *                   type: integer
 *                   description: 受影响的记录数量
 */
 router.delete("/:id", auth.isAdmin, comments.remove);
/**
 * @swagger
 * /comments/{id}:
 *   put:
 *     tags:
 *       - 评论路由
 *     summary: 修改指定ID的评论信息
 *     description: 更新指定评论的详细信息，并返回受影响的记录数
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *           format: int64
 *         description: 需要更新的评论的内部ID
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             $ref: "#/components/schemas/comments"
 *     responses:
 *       200:
 *         description: "请求成功，返回受影响的记录数"
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   format: int32
 *                 msg:
 *                   type: string
 *                 data:
 *                   type: integer
 *                   description: 受影响的记录数量
 */
 router.put("/:id", comments.update);


/**
 * @swagger
 * /comments:
 *   get:
 *     tags:
 *       - 评论路由
 *     summary: 获取评论列表信息
 *     description: 返回系统中的所有评论列表信息，可按需指定查询数量和偏移量
 *     parameters:
 *       - name: limit
 *         in: query
 *         description: 返回结果的数量限制，默认返回全部
 *         required: false
 *         schema:
 *           type: integer
 *       - name: offset
 *         in: query
 *         description: 结果集起始位置偏移量，默认为0
 *         required: false
 *         schema:
 *           type: integer
 *     responses:
 *       200:
 *         description: "请求成功，返回评论列表信息"
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   format: int32
 *                 msg:
 *                   type: string
 *                 data:
 *                   type: array
 *                   items:
 *                     $ref: '#/components/schemas/User'
 */
 router.get("/", comments.findAll);

 /**  
 * @swagger  
 * /comments/useful/{id}:  
 *   patch:  
 *     tags:  
 *       - 评论路由  
 *     summary: 评论有用  
 *     description: 评论有用  
 *     parameters:  
 *       - in: path  
 *         name: id  
 *         required: true  
 *         schema:  
 *           type: integer  
 *         description: 评论的内部ID  
 *     responses:  
 *       200:  
 *         description: "Web成功访问"  
 *         content:  
 *           application/json:  
 *             schema:  
 *               type: object  
 *               properties:  
 *                 code:  
 *                   type: integer  
 *                   format: int32  
 *                 msg:  
 *                   type: string  
 *                 data:  
 *                   type: string
 */
 router.patch("/useful/:id", comments.updateUseful);

 /**  
 * @swagger  
 * /comments/useless/{id}:  
 *   patch:  
 *     tags:  
 *       - 评论路由  
 *     summary: 评论无用  
 *     description: 评论无用  
 *     parameters:  
 *       - in: path  
 *         name: id  
 *         required: true  
 *         schema:  
 *           type: integer  
 *         description: 评论的内部ID  
 *     responses:  
 *       200:  
 *         description: "Web成功访问"  
 *         content:  
 *           application/json:  
 *             schema:  
 *               type: object  
 *               properties:  
 *                 code:  
 *                   type: integer  
 *                   format: int32  
 *                 msg:  
 *                   type: string  
 *                 data:  
 *                   type: string
 */
 router.patch("/useless/:id", comments.updateUseless);



 
 module.exports = router;